package com.lkd.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkd.dto.VmTypeDto;
import com.lkd.entity.VmType;
import com.lkd.mapper.VmTypeMapper;
import com.lkd.service.IVmTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lkd.vo.PageBean;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 售货机类型表 服务实现类
 * </p>
 *
 * @author zzy
 * @since 2025-10-30
 */
@Service
public class VmTypeServiceImpl extends ServiceImpl<VmTypeMapper, VmType> implements IVmTypeService {

    @Override
    public PageBean<VmType> findList(VmTypeDto vmTypeDto) {
        // 1.设置分页参数
        Page<VmType> page = new Page<>(vmTypeDto.getPageIndex(),vmTypeDto.getPageSize());
        // 2.设置查询条件
//        LambdaQueryWrapper<VmType> eq = new LambdaQueryWrapper<VmType>()
//                .eq(VmType::getName, vmTypeDto.getName());
        LambdaQueryWrapper<VmType> wrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<VmType> eq = wrapper.like(ObjectUtil.isNotNull(vmTypeDto.getName())&&ObjectUtil.isNotEmpty(vmTypeDto.getName()),VmType::getName, vmTypeDto.getName());


        // 3.分页查询
        page = this.page(page, eq);
        // 4.组装返回结果
        PageBean<VmType> PageBean = new PageBean<>();
        PageBean.setPageIndex(vmTypeDto.getPageIndex());
        PageBean.setPageSize(vmTypeDto.getPageSize());
        PageBean.setTotalPage(page.getPages());
        PageBean.setTotalCount(page.getTotal());
        PageBean.setCurrentPageRecords(page.getRecords());
        return PageBean;

    }
}
